<?php

/**
 * IndexController
 * 
 * @author
 * @version 
 */

class Admin_NewsController extends Zend_Controller_Action {
	/**
	 * The default action - show the home page
	 */
	public function indexAction() {
        $this->_helper->layout()->enableLayout();
	}
	
	public function postnewsAction(){
		
	}
	
	public function imodAction(){
		$this->_helper->viewRenderer->setNoRender(TRUE);
        $this->_helper->layout()->disableLayout();
        $request = $this->getRequest();
		$params = array_diff($request->getParams(), $request->getUserParams());
        foreach ($params as $colName => $value) {
            $value = is_array($value) ? $value : htmlentities(trim($value));
            $params[$colName] = $value;
        }
        $oper = strtolower($params['oper']);
		switch ($oper) {
            case 'add':
            	$news = new Reale_Model_News();
            	$news->setNews_title($params["news_title"])
            		 ->setNews_summary($params["news_summary"])
            		 ->setNews_body($params["news_body"]);
				if ($news->save()) {
                    echo ' Posted Successfully';
                    return;
                }
                else{
                	throw new Exception('Cannot post news successfully.', Zend_Log::ERR);
                }
            	break;
            default:
            	throw new Zend_Exception('"' . $oper . '" is unknown operation.', 
                Zend_Log::ERR);
                break;	
		}
		throw new Zend_Exception('Operation is not successfull.',Zend_Log::ERR);
	}

}
?>

